package com.java.basis.collection.set;

import java.util.HashSet;
import java.util.Iterator;

/**
 * HashSet集合的使用
 * 存储结构：哈希表（数组+链表+红黑树）
 *
 * @author wangning
 * @create 2021-04-22 21:28
 */
public class TestHashSet02 {
	public static void main(String[] args) {
		HashSet<String> hashSet = new HashSet<>();
		hashSet.add("梁朝伟");
		hashSet.add("林志玲");
		hashSet.add("周润发");
		hashSet.add("刘德华");
		System.out.println("hashSet.toString() = " + hashSet.toString());

		//2.删除数据
		hashSet.remove("刘德华");
		System.out.println("hashSet.toString() = " + hashSet.toString());
		//3.遍历
		for (String s : hashSet) {
			System.out.println("s = " + s);
		}

		Iterator<String> iterator = hashSet.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());

		}
		System.out.println(hashSet.isEmpty());
		System.out.println(hashSet.contains("胡歌"));

	}
}
